www.gusucode.com > VC 中嵌入WORD文档编辑器-源码程序 > VC 中嵌入WORD文档编辑器-源码程序/code/office/CntrItem.cpp

    //Download by http://www.NewXing.com
// CntrItem.cpp : implementation of the COfficeCntrItem class
//

#include "stdafx.h"
#include "office.h"

#include "officeDoc.h"
#include "officeView.h"
#include "CntrItem.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// COfficeCntrItem implementation

IMPLEMENT_SERIAL(COfficeCntrItem, COleDocObjectItem, 0)

COfficeCntrItem::COfficeCntrItem(COfficeDoc* pContainer)
	: COleDocObjectItem(pContainer)
{
	// TODO: add one-time construction code here
	
}

COfficeCntrItem::~COfficeCntrItem()
{
	// TODO: add cleanup code here
	
}

void COfficeCntrItem::OnChange(OLE_NOTIFICATION nCode, DWORD dwParam)
{
	ASSERT_VALID(this);

	COleDocObjectItem::OnChange(nCode, dwParam);

	// When an item is being edited (either in-place or fully open)
	//  it sends OnChange notifications for changes in the state of the
	//  item or visual appearance of its content.

	// TODO: invalidate the item by calling UpdateAllViews
	//  (with hints appropriate to your application)

	GetDocument()->UpdateAllViews(NULL);
		// for now just update ALL views/no hints
}

BOOL COfficeCntrItem::OnChangeItemPosition(const CRect& rectPos)
{
	ASSERT_VALID(this);

	// During in-place activation COfficeCntrItem::OnChangeItemPosition
	//  is called by the server to change the position of the in-place
	//  window.  Usually, this is a result of the data in the server
	//  document changing such that the extent has changed or as a result
	//  of in-place resizing.
	//
	// The default here is to call the base class, which will call
	//  COleDocObjectItem::SetItemRects to move the item
	//  to the new position.

	if (!COleDocObjectItem::OnChangeItemPosition(rectPos))
		return FALSE;

	// TODO: update any cache you may have of the item's rectangle/extent

	return TRUE;
}


void COfficeCntrItem::OnActivate()
{
}

void COfficeCntrItem::OnDeactivateUI(BOOL bUndoable)
{
	COleDocObjectItem::OnDeactivateUI(bUndoable);

    // Hide the object if it is not an outside-in object
    DWORD dwMisc = 0;
    m_lpObject->GetMiscStatus(GetDrawAspect(), &dwMisc);
    if (dwMisc & OLEMISC_INSIDEOUT)
        DoVerb(OLEIVERB_HIDE, NULL);
}

void COfficeCntrItem::Serialize(CArchive& ar)
{
	ASSERT_VALID(this);

	// Call base class first to read in COleDocObjectItem data.
	// Since this sets up the m_pDocument pointer returned from
	//  COfficeCntrItem::GetDocument, it is a good idea to call
	//  the base class Serialize first.
	COleDocObjectItem::Serialize(ar);

	// now store/retrieve data specific to COfficeCntrItem
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

/////////////////////////////////////////////////////////////////////////////
// COfficeCntrItem diagnostics

#ifdef _DEBUG
void COfficeCntrItem::AssertValid() const
{
	COleDocObjectItem::AssertValid();
}

void COfficeCntrItem::Dump(CDumpContext& dc) const
{
	COleDocObjectItem::Dump(dc);
}
#endif

/////////////////////////////////////////////////////////////////////////////

//DEL LPDISPATCH COfficeCntrItem::GetIDispatch()
//DEL {
//DEL       ASSERT_VALID(this); 
//DEL ASSERT(m_lpObject != NULL); 
//DEL LPUNKNOWN lpUnk = m_lpObject; 
//DEL Run(); 
//DEL LPOLELINK lpOleLink = NULL; 
//DEL if (m_lpObject->QueryInterface(IID_IOleLink, (LPVOID FAR*)&lpOleLink) == NOERROR) 
//DEL { 
//DEL ASSERT(lpOleLink != NULL); 
//DEL lpUnk = NULL; 
//DEL if (lpOleLink->GetBoundSource(&lpUnk) != NOERROR) 
//DEL { 
//DEL TRACE0("Warning: Link is not connected!n"); 
//DEL lpOleLink->Release(); 
//DEL return NULL; 
//DEL } 
//DEL ASSERT(lpUnk != NULL); 
//DEL } 
//DEL LPDISPATCH lpDispatch = NULL; 
//DEL if (lpUnk->QueryInterface(IID_IDispatch, (LPVOID FAR*)&lpDispatch)!=NOERROR) 
//DEL { 
//DEL TRACE0("Warning: does not support IDispatch!n"); 
//DEL return NULL; 
//DEL 
//DEL } 
//DEL ASSERT(lpDispatch != NULL); 
//DEL return lpDispatch;
//DEL }

LPDISPATCH COfficeCntrItem::GetIDispatch()
{
  ASSERT_VALID(this); 
ASSERT(m_lpObject != NULL); 
LPUNKNOWN lpUnk = m_lpObject; 
Run(); 
LPOLELINK lpOleLink = NULL; 
if (m_lpObject->QueryInterface(IID_IOleLink, (LPVOID FAR*)&lpOleLink) == NOERROR) 
{ 
ASSERT(lpOleLink != NULL); 
lpUnk = NULL; 
if (lpOleLink->GetBoundSource(&lpUnk) != NOERROR) 
{ 
TRACE0("Warning: Link is not connected!n"); 
lpOleLink->Release(); 
return NULL; 
} 
ASSERT(lpUnk != NULL); 
} 
LPDISPATCH lpDispatch = NULL; 
if (lpUnk->QueryInterface(IID_IDispatch, (LPVOID FAR*)&lpDispatch)!=NOERROR) 
{ 
TRACE0("Warning: does not support IDispatch!n"); 
return NULL; 

} 
ASSERT(lpDispatch != NULL); 
return lpDispatch;
}